package workexp.alg.sword.array;

import javafx.util.Pair;
import org.junit.Test;

public class TwoCordSearch {
  int num[][] = {
          {1,4,6,28},
          {2,7,32,40},
          {10,11,67,79}};

  public Pair<Integer,Integer> search(int[][] num,int target){
       Pair<Integer,Integer> result =null;
       int x=0,y=0;
       int ylen = num.length;
       int xlen = num[0].length;

       x=0;
       y=ylen-1;

        while(x<xlen&&y<ylen){
            if(num[y][x]<target){
                x+=1;
            }else if(num[y][x]>target){
                y-=1;
            }else if(num[y][x]==target){
                return new Pair<>(x+1,y+1);
            }
        }

      return result;
  }

  @Test
    public void test(){
      Pair<Integer,Integer> result = search(num,11);
      System.out.println(result.toString());
  }

}
